package com.hfmall.provider;

import com.hfmall.entity.HfOrder;
import org.apache.ibatis.jdbc.SQL;

public class OrderProvider {
    public String select(HfOrder order){
        return new SQL(){
            {
                SELECT("*");
                FROM("hf_order");
                if (order!=null) {
                    if (order.getName() != null && order.getName().length() != 0) {
                        WHERE("name='" + order.getName() + "'");
                    }
                    if (order.getPhone() != null ) {
                        WHERE("phone='" + order.getPhone() + "'");
                    }
                    if (order.getAddress() != null ) {
                        WHERE("address='" + order.getAddress() + "'");
                    }
                    if (order.getPayMoney()!= null ) {
                        WHERE("paymoney='" + order.getPayMoney() + "'");
                    }
                    if (order.getOrderNo()!= null ) {
                        WHERE("order_no like'" + "%"+order.getOrderNo()+"%"+ "'");
                    }
                    if (order.getStatus()!=null&& order.getStatus().length() != 0){
                        WHERE("status='" + order.getStatus()+ "'");
                    }
                    if (order.getStartTime()!=null&&order.getEndTime()!=null){
                        WHERE("create_date>='" + order.getStartTime()+ "'");
                    }
                    if (order.getStartTime()!=null&&order.getEndTime()!=null){
                        WHERE("create_date<='" + order.getEndTime()+ "'");
                    }
                    if (order.getPayTime()!=null) {
                        WHERE("pay_time='" + order.getPayTime() + "'");
                    }
                }
            }
        }.toString();
    }
}
